#ifndef MEM0RY_H
#define MEMORY_H
#include "type.h"
#include "v_cpu.h"

const unsigned int BIOS_ROM_SIZE = (1 << 19);
const unsigned int EXTEND_ROM_SIZE = 0x20000;
const unsigned int BIOS_ROM_SIZE_SHIFT = BIOS_ROM_SIZE - 1;
const unsigned int EXTEND_ROM_SIZE_SHIFT = EXTEND_ROM_SIZE - 1;
const unsigned int MEM_VECTOR_ALIGN = 4096;

#define US_FLAG 0x04
#define RW_FLAG 0x02
#define P_FLAG  0x01

class avm_memory {
public:
	avm_memory(unsigned size = 0x100000);
	~avm_memory();
	bit32u get_size() {
		return memsize;
	}	
	bit8u *get_vector(avm_phy_addr addr);
	void read_physical_page(v_cpu *cpu, avm_phy_addr addr, bit32u len, void *p_buffer);
	void write_physical_page(v_cpu *cpu, avm_phy_addr addr, bit32u len, void *p_buffer);

private:
	void init_memory(bit32u, bit32u);
	bit8u *actual_vector;
	bit8u *vector; // After correctly aligned
	bit8u *rom;		// 512K BIOS + 128K extension
	bit8u *bogus;
	bit32u memsize;
};


#endif
